const app = getApp()

Page({
  data: {
    list:[{
      name:"星期一",
      id:1,
      course:[{
        id:11,
        title:"马克思主义原理",
        short:"Mk",
        time:"9:00"
      },{
        id:12,
        title:"计算机概论",
        short:"Js",
        time:"11:00"
      },{
        id:13,
        title:"管理概论",
        short:"Gl",
        time:"14:00"
      },{
        id:14,
        title:"大学英语",
        short:"En",
        time:"16:00"
      }]
    },{
      name:"星期二",
      id:2,
      course:[{
        id:11,
        title:"心理学",
        short:"Xl",
        time:"9:00"
      },{
        id:12,
        title:"计算机网路",
        short:"Js",
        time:"11:00"
      },{
        id:13,
        title:"管理概论",
        short:"Gl",
        time:"14:00"
      },{
        id:14,
        title:"大学英语",
        short:"En",
        time:"16:00"
      }]
    },{
      name:"星期三",
      id:3,
      course:[{
        id:11,
        title:"算法与数据结构",
        short:"Sf",
        time:"9:00"
      },{
        id:12,
        title:"计算机网路",
        short:"Js",
        time:"11:00"
      },{
        id:13,
        title:"管理概论",
        short:"Gl",
        time:"14:00"
      },{
        id:14,
        title:"大学英语",
        short:"En",
        time:"16:00"
      }]
    },{
      name:"星期四",
      id:4,
      course:[{
        id:11,
        title:"算法与数据结构",
        short:"Sf",
        time:"9:00"
      },{
        id:12,
        title:"计算机网路",
        short:"Js",
        time:"11:00"
      }]
    },{
      name:"星期五",
      id:5,
      course:[{
        id:11,
        title:"数据结构",
        short:"Sj",
        time:"9:00"
      }]
    },],
    listCur:{
      name:"星期一",
      id:1
    },
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    TabCur: 0,
    MainCur: 0,
    VerticalNavTop: 0,
    load: true
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      MainCur: e.currentTarget.dataset.id,
      VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
    })
  },
  VerticalMain(e) {
    let that = this;
    let list = this.data.list;
    let tabHeight = 0;
    if (this.data.load) {
      for (let i = 0; i < list.length; i++) {
        let view = wx.createSelectorQuery().select("#main-" + list[i].id);
        view.fields({
          size: true
        }, data => {
          list[i].top = tabHeight;
          tabHeight = tabHeight + data.height;
          list[i].bottom = tabHeight;     
        }).exec();
      }
      that.setData({
        load: false,
        list: list
      })
    }
    let scrollTop = e.detail.scrollTop + 20;
    for (let i = 0; i < list.length; i++) {
      if (scrollTop > list[i].top && scrollTop < list[i].bottom) {
        that.setData({
          VerticalNavTop: (list[i].id - 1) * 50,
          TabCur: list[i].id
        })
        return false
      }
    }
  }
})
